package com.nd.mobile.study.common.util;

import android.content.Context;

public class ProxyTool {

	public static String		CURRENT_TYPE_FLOW	= "";

	public static ProxyNetType	CURRENT_NET_TYPE	= ProxyNetType.NONE;

	public static String		WIFI				= "wifi";

	public static String		MOBILE				= "mobile";

	public static void setCurrConnectionType(Context context) {
		if (NetworkUtil.isMobileConnection(context)) {
			CURRENT_TYPE_FLOW = MOBILE;
		} else {
			CURRENT_TYPE_FLOW = WIFI;
		}
	}
/*
	public static void setCurrNetType(Context context) {
		ConnectivityManager conManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = conManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		NetworkInfo activeInfo = conManager.getActiveNetworkInfo();
		App.ONLINE_FLAG = (activeInfo != null) && (activeInfo.isAvailable());
		
		String apn = info.getExtraInfo();
		if (!StringUtils.isBlank(apn)) {
			ProxyNetType type = ProxyNetType.getNetTypeByNetName(apn.toLowerCase());
			ProxyTool.CURRENT_NET_TYPE = type;
		}
	}*/

	public enum ProxyNetType {
		// 无代理
		NONE("", "", 0),
		// cmwap
		CMWAP("cmwap", "10.0.0.172", 80),
		// uniwap
		UNIWAP("uniwap", "10.0.0.172", 80),
		// unicom 3gwap
		UNI3GWAP("3gwap", "10.0.0.172", 80);

		// 网络类型名称
		private final String	type;

		// IP地址
		private final String	ip;

		// 端口
		private final int		port;

		private ProxyNetType(String type, String ip, int port) {
			this.type = type;
			this.ip = ip;
			this.port = port;
		}

		public String getType() {
			return type;
		}

		public String getIp() {
			return ip;
		}

		public int getPort() {
			return port;
		}

		/**
		 * 
		 * 作用: 参数:
		 * 
		 * @param C
		 * @return
		 */
		/**
		 * 功能描述 : 依据手机接入点名称获取代理类型枚举
		 * <p>
		 * 调用示例:
		 * 
		 * <pre>
		 * </pre>
		 * 参数说明：
		 * <p>
		 * 
		 * @param innetName
		 *            onnectiveManager获取的接入点名称，转换为小写
		 * @return 返回值：
		 *         <p>
		 *         ProxyNetType
		 */
		public static ProxyNetType getNetTypeByNetName(String innetName) {
			for (ProxyNetType type : ProxyNetType.values()) {
				if (type.getType().equals(innetName)) {
					return type;
				}
			}
			return NONE;
		}
	}
}
